package com.example.backend.controller;

import com.example.backend.common.ResultMessage;
import com.example.backend.entity.XiangQing;
import com.example.backend.service.IXiangQingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/xiangqing")
public class XiangQingController {
    @Autowired
    private IXiangQingService xiangQingService;

    @PostMapping
    public ResultMessage addXiangQing(@RequestBody XiangQing xiangQing) {
        if(xiangQingService.addXiangQing(xiangQing)){
            return ResultMessage.success(null,"新增成功");
        }
        return ResultMessage.error("新增失败");
    }

    @DeleteMapping("/{xqid}")
    public ResultMessage deleteXiangQing(@PathVariable("xqid") Integer xqid) {
        if(xiangQingService.deleteXiangQing(xqid)){
            return ResultMessage.success(null,"删除成功");
        }
        return ResultMessage.error("删除失败");
    }

    @PutMapping
    public ResultMessage updateXiangQing(@RequestBody XiangQing xiangQing) {
        if(xiangQingService.updateXiangQing(xiangQing)){
            return ResultMessage.success(null,"更新成功");
        }
        return ResultMessage.error("更新失败");
    }

    @GetMapping
    public ResultMessage queryXiangQing() {
        return ResultMessage.success(xiangQingService.queryXiangQing(),"查询成功");
    }

    @GetMapping("/{xqid}")
    public ResultMessage queryXiangQingById(@PathVariable("xqid") Integer xqid) {
        return ResultMessage.success(xiangQingService.queryXiangQingById(xqid),"查询成功");
    }

    @GetMapping("/byddid/{ddid}")
    public ResultMessage queryXiangQingByDdid(@PathVariable("ddid") Integer ddid) {
        return ResultMessage.success(xiangQingService.queryXiangQingByDdid(ddid),"查询成功");
    }
}
